var sum;
var counts='';
var pageThis =0;
var pagecount = 5;
var index = 0;
var type = JSON.parse(sessionStorage.getItem("type1")) || 0;
var bookid='';
var chapterId='';
var sectionId=''
var wheretext = '';
var filetype='';
/*$.ajaxSetup({ async: false });*/

var zNodes = new Array();

var setting = {
    view: {
        addHoverDom: addHoverDom,
        removeHoverDom: removeHoverDom,
        selectedMulti: false
    },
    check: {
        enable: false
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    edit: {
        enable: true
    },
    callback: {
        onClick: zTreeOnClick
    }
};

$(function () {
    $(".content_left").css("height",$(".content_right").height());

    getCourseName();

    bookid = $("#chooseTest").children("option:selected").attr("data-typeid");

   console.log(bookid)
    //判断5种课的不同
    $("#chooseTest").children('option').eq(type).attr("selected","selected");
    if(type=="0"||type=="1"||type=="2"||type=="3"){
        $(".pl-leftT").text("章节目录");
        parent.$(".changeTest").attr("href","../poolMana/poolYjskc.html");
        var strhref = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=8';
        var strhref1 = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=7';
        $(".lilunAdd").attr("href",strhref);
        $(".educationAdd").attr("href",strhref1);

    }else if(type=="4"){
        parent.$(".changeTest").attr("href","../poolMana/poolGgzyk.html");

    }else if(type=="5"){
        parent.$(".changeTest").attr("href","../poolMana/poolZjjs.html");
    }else if(type=="6"){
        $(".pl-leftT").text("教材大纲");
        parent.$(".changeTest").attr("href","../poolMana/poolYjskc.html");
        var strhref = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=8';
        var strhref1 = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=7';
        $(".lilunAdd").attr("href",strhref);
        $(".educationAdd").attr("href",strhref1);
    }

    $("#chooseTest").change(function(){
        var p1=$(this).children('option:selected').attr("data-id");
        if(p1=="0"||p1=="1"||p1=="2"||p1=="3"||p1=="6"){
            sessionStorage.setItem("type1",JSON.stringify(p1));
            self.location.href='poolYjskc.html';
            var strhref = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=8';
            var strhref1 = '../informationMana/addNews.html?type=commonNews&bookId='+bookid+'&commonNewsTypeId=7';
            $(".lilunAdd").attr("href",strhref);
            $(".educationAdd").attr("href",strhref1);
        }else if(p1=="4"){
            sessionStorage.setItem("type1",JSON.stringify(p1));
            self.location.href='poolGgzyk.html'
        }else if(p1=="5"){
            sessionStorage.setItem("type1",JSON.stringify(p1));
            self.location.href='poolZjjs.html';
        }
    })

    // 获取章节点
    getChapterByBookId(bookid);

    //得到理论前沿
     getqianYan();//没有章 commonNews 有章commonResource

    //得到教学案例
    geteducationExample();

    $(".searchNameInput").keypress(function(e) {
        // 回车键事件
        if(e.which == 13) {
            e.preventDefault();
            getqianYan();
        }
    });

    $(".searchNameInput2").keypress(function(e) {
        // 回车键事件
        if(e.which == 13) {
            e.preventDefault();
            getQuestion();
        }
    });

    $(".searchNameInput3").keypress(function(e) {
        // 回车键事件
        if(e.which == 13) {
            e.preventDefault();
            geteducationExample();
        }
    });

    $('#editTestT').on('shown.bs.modal', function () {
        $(".bookName").val($("#chooseTest").children("option:selected").text())
    })

    $('#editPoint').on('shown.bs.modal', function () {
        $(".pointDiv").val($(".py-mainPinfo").html())
    })



  /*  $(".addresourceBtn").click(function(){
        if($("#InputFile").val()!=""&&$("#InputFile").val()!=null&&$("#InputFile").val()!=undefined){
            var formData1 = new FormData();
            formData1.append("bookId", bookid);
            formData1.append("file", $("#InputFile")[0].files[0]);
            formData1.append("title", $(".fileName").val());
            formData1.append("type",filetype);
            formData1.append("sectionId",sectionId);
            $.ajax({
                type : 'POST',
                url : basePath+'/super/common/zhejiang/addCommonResource',
                data : formData1,
                cache:false,
                processData : false,
                contentType : false,
                success : function(result) {
                   //console.log(filetype);
                    alert("添加成功！");
                    if(filetype=="VIDEO_MATERIAL"){
                        index=$("#shipingPage").find(".active").find("a").text()-1;
                        if(index!=-1&&index!=null&&index!=undefined&&index!=""){
                            getVideo();
                        }else{
                            index=0;
                            getVideo();
                        }
                    }
                    else if(filetype=="DOCUMENT_MATERIAL"){
                        index=$("#wengdangPage").find(".active").find("a").text()-1;
                        if(index!=-1&&index!=null&&index!=undefined&&index!=""){
                            getdocument();
                        }else{
                            index=0;
                            getdocument();
                        }
                    }else if(filetype=="OTHER_MATERIAL"){

                        index=$("#otherPage").find(".active").find("a").text()-1;
                       //console.log(index);
                        if(index!=-1&&index!=null&&index!=undefined&&index!=""){
                            getotheResource();
                        }else{
                            index=0;
                            getotheResource();
                        }
                    }else if(filetype=="WONDERFUL_LESSON"){
                        index=$("#jingcaiPage").find(".active").find("a").text()-1;
                        if(index!=-1&&index!=null&&index!=undefined&&index!=""){
                            getjingcai();
                        }else{
                            index=0;
                            getjingcai();
                        }
                    }
                },
                error : function(err) {
                    alert("添加失败！");
                }
            });
            $("#addFile").modal("hide");
        }else{
            confirm("请先选择文件！")
        }

    })*/

});

// 根据书本ID获取章节点
function getChapterByBookId(bookId) {
    var data = {
        bookId: bookId
    };
    console.log(data);
    AjaxSubmit("GET", data, basePath + "/super/common/zhejiang/getChapterByBookId", getChapterByBookIdResult);
}
function getChapterByBookIdResult(res) {
    console.log(res);
    if (res.status == "SUCCESS") {
        var resultData = res.obj;
        for (var i = 0; i < resultData.length; i++) {
            var zNode = {
                id: resultData[i].id,
                pId: 0,
                name: resultData[i].title,
                truename: strEllipsis(resultData[i].title,6)
            };

            zNodes.push(zNode);

            var data = {
                chapterId: zNode.id
            }
            AjaxSubmit2("GET", juge(data), basePath + "/super/common/zhejiang/getSectionByChapterId", getSectionByChapterIdResult);
        }

        chapterId=resultData[0].id;


        initChapterResource();
    }
}
function getSectionByChapterIdResult(res) {
    console.log(res);
    if (res.status == "SUCCESS") {
        var resultData = res.obj;
        for (var i = 0; i < resultData.length; i++) {
            var zNode = {
                id: resultData[i].id+1000,
                pId: resultData[i].chapterId,
                name: resultData[i].title,
                truename: strEllipsis(resultData[i].title,6)
            };
            zNodes.push(zNode);
        }
        if(resultData.length!=0){
            sectionId = resultData[0].id;
        }
        console.log(sectionId)

        $.fn.zTree.init($("#treeDemo"), setting, zNodes);

        initSectionResource();
    }
}
function initSectionResource() {
    // 得到视屏素材等其他素材
    getVideo(); // 得到视频素材

    getdocument(); // 得到文档素材

    getotheResource(); // 得到其他素材

    getjingcai(); // 得到精彩一课
}
function initChapterResource() {
    //得到答疑解惑
    getQuestion();
}

//得到前沿
function getqianYan(){
    wheretext=$.trim($(".searchNameInput").val());
    var  data={page: index ,size: pagecount,commonNewsTypeId:8,bookId:bookid,title:wheretext};
    AjaxSubmit("GET",juge(data), basePath + "/super/common/zhejiang/searchCommonNews",searchCommonNews_fun1);
}
function searchCommonNews_fun1(res){
   console.log(res);
    if(res.status=='SUCCESS'){
        var newsLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (newsLists.length != 0) {
            $("#lilunPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#lilunPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getqianYan();
                    pageThis = num;
                }
            });
            $(".lilunTbody").empty();
            $('.warnDiv').remove();
            $.each(newsLists, function (i, newsList) {
                var zhaiyao = newsList.abstructContent || '';
                var createTime = newsList.creatTime || '';
                var statustr = '';
                if(newsList.status=='DOWN'){//未发布
                    statustr='未发布 |<span class="cursorP colorBlue" data-newstypeId="8" data-id="'+newsList.id+'"  onclick="changeStatu(this)"> 发布</span>'
                }else if(newsList.status=='UP'){ //已发布
                    statustr='已发布|<span class="cursorP colorBlue" data-newstypeId="8" data-id="'+newsList.id+'"  onclick="changeStatu2(this)"> 关闭</span>'
                }
                var html = '<tr> ' +
                    '<td>'+newsList.title+'</td> ' +
                    '<td>'+zhaiyao+'</td> ' +
                    '<td>'+createTime+'</td> ' +
                    '<td>'+statustr+'</span></td> ' +
                    '<td class="texC ">  <a   class="texC  cursorP colorBlue" href="../informationMana/addNews.html?type=commonNews&commonNewsTypeId=8&bookId='+bookid+'&needUpdate=1&nid='+newsList.id+'">编辑</a> | <span class=" cursorP colorBlue" data-id="'+newsList.id+'" data-newstypeId="8" onclick="deleteNews(this)" >删除</span></td> ' +
                    '</tr>';
                $(".lilunTbody").append(html)
            })

        }
        else{
            $("#lilunPage").css("display","none");
            $(".lilunTbody").empty();
            $('.warnDiv').remove();
            var html = $('<div class="text-center  warnDiv"  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".lilunTable").after(html)
        }
    }
}


function geteducationExample(){
    wheretext=$.trim($(".searchNameInput3").val());
    var  data={page: index ,size: pagecount,commonNewsTypeId:7,bookId:bookid,title:wheretext};
   //console.log(data);
    AjaxSubmit("GET",juge(data), basePath + "/super/common/zhejiang/searchCommonNews",searchCommonNews_fun2);
}
function searchCommonNews_fun2(res){
   //console.log(res);
    if(res.status=='SUCCESS'){
        var newsLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (newsLists.length != 0) {
            $("#educationPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#educationPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    geteducationExample();
                    pageThis = num;
                }
            });
            $(".educationTbody").empty();
            $('.warnDiv2').remove();
            $.each(newsLists, function (i, newsList) {
                var zhaiyao = newsList.abstructContent || '';
                var createTime = newsList.creatTime || '';
                var statustr = '';
                if(newsList.status=='DOWN'){//未发布
                    statustr='未发布 |<span class="cursorP colorBlue" data-newstypeId="7" data-id="'+newsList.id+'"  onclick="changeStatu(this)"> 发布</span>'
                }else if(newsList.status=='UP'){ //已发布
                    statustr='已发布|<span class="cursorP colorBlue" data-newstypeId="7" data-id="'+newsList.id+'"  onclick="changeStatu2(this)"> 关闭</span>'
                }
                var html = '<tr> ' +
                    '<td>'+newsList.title+'</td> ' +
                    '<td>'+zhaiyao+'</td> ' +
                    '<td>'+createTime+'</td> ' +
                    '<td>'+statustr+'</span></td> ' +
                    '<td class="texC ">  <a   class="texC  cursorP colorBlue" href="../informationMana/addNews.html?type=commonNews&commonNewsTypeId=7&bookId='+bookid+'&needUpdate=1&nid='+newsList.id+'">编辑</a> | <span class=" cursorP colorBlue" data-id="'+newsList.id+'" data-newstypeId="7" onclick="deleteNews(this)" >删除</span></td> ' +
                    '</tr>';
                $(".educationTbody").append(html)
            })

        }
        else{
            $("#educationPage").css("display","none");
            $(".educationTbody").empty();
            $('.warnDiv2').remove();
            var html = $('<div class="text-center  warnDiv2 "  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".educationTable").after(html)
        }
    }
}


//得到问题
function getQuestion(){
    wheretext=$.trim($(".searchNameInput2").val());
    var  data={page: index ,size: pagecount,chapterId:chapterId,bookId:bookid,question:wheretext,type:'BOOK'};
   /*console.log(data)*/
    AjaxSubmit("GET",juge(data), basePath + "/super/common/theResource/searchAnswerDoubts",searchAnswerDoubts_fun);
}
//传TYPE  BOOK
function searchAnswerDoubts_fun(res){
   /*console.log(res);*/
    var typeBooknum = 0;
    if(res.status=='SUCCESS'){
        var newsLists = res.obj.content;
        sum = res.obj.totalElements;
       //console.log(sum);
        counts = sum / pagecount;
        if (newsLists.length != 0) {
            $("#questionPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#questionPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getQuestion();
                    pageThis = num;
                }
            });
            $(".questionTBody").empty();
            $('.warnDiv3').remove();
            $.each(newsLists, function (i, newsList) {
                if(newsList.type=='BOOK'){
                    var  answer= newsList.answer || '';
                    var question = newsList.question || '';
                    var html = '<tr> ' +
                        '<td>'+question+'</td> ' +
                        '<td>'+answer+'</span></td> ' +
                        ' <td class="texC colorBlue">  <span class="texC  cursorP"  data-id="'+newsList.id+'" onclick="editQuestion(this)">编辑</span> | <span class=" cursorP" onclick="deleteQuestion(this)" data-quesid="'+newsList.id+'">删除</span></td> ' +
                        '</tr>';
                    $(".questionTBody").append(html)
                }
            })

        }
        else{
            $("#questionPage").css("display","none");
            $(".questionTBody").empty();
            $('.warnDiv3').remove();
            var html = $('<div class="text-center  warnDiv3 "  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".questionTable").after(html)
        }
    }
}

//删除答疑解惑
function deleteQuestion(btn){
    var msg = "您真的确定要删除吗？\n\n请确认！";
    if (confirm(msg)==true){
        var quesid = $(btn).attr("data-quesid");
        var  data2={answerDoubtsId:quesid};
        AjaxSubmit("POST",data2, basePath + "/super/common/theResource/deleteAnswerDoubts",deleteAnswerDoubts_fun);
        function deleteAnswerDoubts_fun(res){
            if(res.status=='SUCCESS') {
                index=0;
                getQuestion();
            }
        }
    }else{
        return false;
    }
}
/*新增答疑解惑*/
function saveQues(){
    var answer1 =  $(".answer1").val();
    var question1 =  $(".question1").val();
    var  data={chapterId:chapterId,bookId:bookid,question:question1,answer:answer1,type:'BOOK'};
   /* console.log(data);*/
    if(answer1!=""&&answer1!=undefined&&answer1!=null&&question1!=""&&question1!=null&&question1!=undefined){
        AjaxSubmit("POST",juge(data), basePath + "/super/common/theResource/addAnswerDoubts",addAnswerDoubts_fun);
        $("#addQues").modal("hide");
    }else{
        alert("问题或答案不能为空！")
    }

}
function addAnswerDoubts_fun(res){
   /* console.log(res)*/
    if(res.status=='SUCCESS') {
        index=$("#questionPage").find(".active").find("a").text()-1;
        getQuestion();
    }
}

var tempData="";
//编辑答疑解惑
function editQuestion(btn){
    $("#editQues").modal('show');
    var quesid = $(btn).attr("data-id");


    //答疑解惑编辑
    $('#editQues').on('shown.bs.modal', function () {
        var  data={answerDoubtsId:quesid};
       //console.log(data);
        AjaxSubmit("GET",juge(data), basePath + "/super/common/theResource/getAnswerDoubtsById",getAnswerDoubtsById_fun);
        function getAnswerDoubtsById_fun(res){
            if(res.status=='SUCCESS') {
                tempData=res.obj;
                var answer = res.obj.answer ||'';
                var question = res.obj.question ||'';
                $(".question").val(question);
                $(".answer").val(answer);
            }
        }
    })
}

//保存编辑答疑解惑
function saveEditQues(btn){
    var answer1 =  $(".answer").val();
    var question1 =  $(".question").val();
    tempData.answer=answer1;
    tempData.question=question1;
   // var  data={chapterId:chapterId,bookId:bookid,question:question1,answer:answer1,id};

    AjaxSubmit("POST",juge(tempData), basePath + "/super/common/theResource/updateAnswerDoubts",updateAnswerDoubts_fun);
    $("#editQues").modal('hide');
    function updateAnswerDoubts_fun(res){
       //console.log(res)
        if(res.status=='SUCCESS') {
            index =$("#questionPage").find(".active").find("a").text()-1;
            getQuestion();
        }
    }
}
//得到视屏素材
function  getVideo(){
    var  data={page: index ,size: pagecount,type:'VIDEO_MATERIAL',bookId:bookid,sectionId:sectionId};
   console.log(data);
    AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/searchCommonResource",searchCommonResource_fun1);
}
function searchCommonResource_fun1(res){
   console.log(res);
    if(res.status=='SUCCESS'){
        var fileLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (fileLists.length != 0) {
            $("#shipingPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#shipingPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getVideo();
                    pageThis = num;
                }
            });
            $(".shipingTbody").empty();
            $(".warnDiv4").remove();
            $.each(fileLists, function (i, fileList) {
                var number = fileList.number ||'';
                var  data={sectionId:fileList.sectionId};
                console.log(data);
                AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/getSectionBySectionId",getSectionBySectionId_fun);
                function getSectionBySectionId_fun(res){
                  /*  console.log(res);*/
                    var html = '  <tr> ' +
                        '<td>'+number+'</td> ' +
                        '<td>'+fileList.title+'</td> ' +
                        '<td>'+res.obj.title+'</td> ' +
                        '<td class="texC colorBlue"><span class=" cursorP" data-type="VIDEO_MATERIAL" onclick="deleteResource(this)" data-id="'+fileList.id+'">删除</span></td> </tr>';
                    $(".shipingTbody").append(html)
                }
            })

        }
        else{
            $("#shipingPage").css("display","none");
            $(".shipingTbody").empty();
            $('.warnDiv4').remove();
            var html = $('<div class="text-center warnDiv4"  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".shipingTable").after(html)
        }
    }
}

//得到文档素材
function  getdocument(){
    var  data={page: index ,size: pagecount,type:'DOCUMENT_MATERIAL',bookId:bookid,sectionId:sectionId};
   //console.log(data);
    AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/searchCommonResource",searchCommonResource_fun2);
}
function searchCommonResource_fun2(res){
   //console.log(res);
    if(res.status=='SUCCESS'){
        var fileLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (fileLists.length != 0) {
            $("#wengdangPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#wengdangPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getdocument();
                    pageThis = num;
                }
            });
            $(".wengdangTbody").empty();
            $(".warnDiv5").remove();
            $.each(fileLists, function (i, fileList) {
                var number = fileList.number ||'';
                var  data={sectionId:fileList.sectionId};
                console.log(data);
                AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/getSectionBySectionId",getSectionBySectionId_fun);
                function getSectionBySectionId_fun(res){
                    /*  console.log(res);*/
                    var html = '  <tr> ' +
                        '<td>'+number+'</td> ' +
                        '<td>'+fileList.title+'</td> ' +
                        '<td>'+res.obj.title+'</td> ' +
                        '<td class="texC colorBlue"><span class=" cursorP" data-type="DOCUMENT_MATERIAL" onclick="deleteResource(this)" data-id="'+fileList.id+'">删除</span></td> </tr>';
                    $(".wengdangTbody").append(html)
                }

            })

        }
        else{
            $("#wengdangPage").css("display","none");
            $(".wengdangTbody").empty();
            $(".warnDiv5").remove();
            var html = $('<div class="text-center warnDiv5"  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".wengdangTable").after(html)
        }
    }
}

//得到其他素材
function   getotheResource(){
    var  data={page: index ,size: pagecount,type:'OTHER_MATERIAL',bookId:bookid,sectionId:sectionId};
   //console.log(data);
    AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/searchCommonResource",searchCommonResource_fun3);
}
function searchCommonResource_fun3(res){
   //console.log(res);
    if(res.status=='SUCCESS'){
        var fileLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (fileLists.length != 0) {
            $("#otherPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#otherPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getotheResource();
                    pageThis = num;
                }
            });
            $(".otherTbody").empty();
            $(".warnDiv6").remove();
            $.each(fileLists, function (i, fileList) {
                var number = fileList.number ||'';
                var  data={sectionId:fileList.sectionId};
                console.log(data);
                AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/getSectionBySectionId",getSectionBySectionId_fun);
                function getSectionBySectionId_fun(res){
                    /*  console.log(res);*/
                    var html = '  <tr> ' +
                        '<td>'+number+'</td> ' +
                        '<td>'+fileList.title+'</td> ' +
                        '<td>'+res.obj.title+'</td> ' +
                        '<td class="texC colorBlue"><span class=" cursorP" data-type="OTHER_MATERIAL" onclick="deleteResource(this)" data-id="'+fileList.id+'">删除</span></td> </tr>';
                    $(".otherTbody").append(html)
                }
            })

        }
        else{
            $("#otherPage").css("display","none");
            $(".otherTbody").empty();
            $(".warnDiv6").remove();
            var html = $('<div class="text-center warnDiv6"  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".otherTable").after(html)
        }
    }
}
//得到精彩一课
function   getjingcai(){
    var  data={page: index ,size: pagecount,type:'WONDERFUL_LESSON',bookId:bookid,sectionId:sectionId};
   //console.log(data);
    AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/searchCommonResource",searchCommonResource_fun4);
}
function searchCommonResource_fun4(res){
   //console.log(res);
    if(res.status=='SUCCESS'){
        var fileLists = res.obj.content;
        sum = res.obj.totalElements;
        counts = sum / pagecount;
        if (fileLists.length != 0) {
            $("#jingcaiPage").css("display","block");
            if (sum % pagecount == 0) {
                counts = parseInt(sum / pagecount);
            }
            else {
                counts = parseInt(sum / pagecount) + 1;
            }
            $("#jingcaiPage").paging({
                pageNo: pageThis,
                totalPage: counts,
                totalSize: sum,
                callback: function (num) {
                   //console.log(num);
                    index = num - 1;
                    getjingcai();
                    pageThis = num;
                }
            });
            $(".jingcaiTbody").empty();
            $(".warnDiv7").remove();
            $.each(fileLists, function (i, fileList) {
                var number = fileList.number ||'';
                var  data={sectionId:fileList.sectionId};
                console.log(data);
                AjaxSubmit("GET",data, basePath + "/super/common/zhejiang/getSectionBySectionId",getSectionBySectionId_fun);
                function getSectionBySectionId_fun(res){
                    /*  console.log(res);*/
                    var html = '  <tr> ' +
                        '<td>'+number+'</td> ' +
                        '<td>'+fileList.title+'</td> ' +
                        '<td>'+res.obj.title+'</td> ' +
                        '<td class="texC colorBlue"><span class=" cursorP" data-type="WONDERFUL_LESSON" onclick="deleteResource(this)" data-id="'+fileList.id+'">删除</span></td> </tr>';
                    $(".jingcaiTbody").append(html)
                }

            })

        }
        else{
            $("#jingcaiPage").css("display","none");
            $(".jingcaiTbody").empty();
            $(".warnDiv7").remove();
            var html = $('<div class="text-center warnDiv7"  style="width: 100%;margin: 73px 0px;font-size: 14px" >无信息!</div>');
            $(".jingcaiTable").after(html)
        }
    }
}

//增加素材需修改 章节问题
function addresource(btn){
    $("#addFile").modal("toggle");
    $(".easy_upload_upbtn").show();
     filetype = $(btn).attr("data-type");
    $('#easyContainer').easyUpload({
        allowFileTypes: '*',//允许上传文件类型，格式';*.doc;*.pdf'
        allowFileSize: 2000000,//允许上传文件大小(KB)
        selectText: '选择文件',//选择文件按钮文案
        multi: false,//是否允许多文件上传
        multiNum: 5,//多文件上传时允许的文件数
        showNote: false,//是否展示文件上传说明
        note: '提示：最多上传5个文件，支持格式为doc、pdf、jpg',//文件上传说明
        showPreview: false,//是否显示文件预览
        url: basePath+'/super/common/zhejiang/addCommonResource',//上传文件地址
        fileName: 'file',//文件filename配置参数
        formParam: {
            bookId: bookid,
            type: filetype,
            sectionId:sectionId
        },//文件filename以外的配置参数，格式：{key1:value1,key2:value2}
        timeout:6000000,//请求超时时间
        okCode: 1000,//与后端返回数据code值一致时执行成功回调，不配置默认200
        successFunc: function(res) {
            index = $(btn).parent().next().find(".pagination").find(".active").find("a").text()-1;
            if(filetype=="VIDEO_MATERIAL"){
                getVideo();
            }else if(filetype=="DOCUMENT_MATERIAL"){
                getdocument();
            }else if(filetype=="OTHER_MATERIAL"){
                getotheResource();
            }else if(filetype=="WONDERFUL_LESSON"){
                getjingcai();
            }
         /*   setTimeout(function(){
                $("#addFile").modal("hide");
                location.reload();
            },2000)*/
        },//上传成功回调函数
        errorFunc: function(res) {
        },//上传失败回调函数
        deleteFunc: function(res) {

        }//删除文件回调函数
    })
}
function getTime() {
    setTimeout(function () {
        var duration = $("#video")[0].duration;
        if(isNaN(duration)){
            getTime();
        }
        else{
            console.info("该歌曲的总时间为："+$("#video")[0].duration+"秒");
        }
    }, 10);
}

<!--把文件转换成可读URL-->
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}
//删除文件
function deleteResource(btn){
    var msg = "您真的确定要删除吗？\n\n请确认！";
    if (confirm(msg)==true){
        var newsId = $(btn).attr("data-id");
        var  data={commonResourceId: newsId};
       //console.log(data);
        var type = $(btn).attr("data-type");
        AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/deleteCommonResource",deleteCommonResource_fun);
        function deleteCommonResource_fun(res){
                //console.log(res);
            if(res.status=='SUCCESS'){
                index=0;
               /* index = $(btn).parent().parent().parent().parent().next().find(".pagination").find(".active").find("a").text()-1;*/
                if(type=="VIDEO_MATERIAL"){
                  /*  index=0;*/
                    getVideo();
                }else if(type=="DOCUMENT_MATERIAL"){
                  /*  index=0;*/
                    getdocument();
                }else if(type=="OTHER_MATERIAL"){
                  /*  index=0;*/
                    getotheResource();
                }else if(type=="WONDERFUL_LESSON"){
                /*    index=0;*/
                    getjingcai();
                }
            }
        }
    }else{
        return false;
    }
}
//编辑书的要点
function editBookPoint(){
    var mainPointsOfTeaching = $(".pointDiv").val();
    var  data={bookId:bookid,mainPointsOfTeaching:mainPointsOfTeaching};
   //console.log(data);
    AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/updateBookMainPointsOfTeaching",updateBookMainPointsOfTeaching_fun);
    $("#editPoint").modal("hide");

}
function updateBookMainPointsOfTeaching_fun(res){
   //console.log(res);
    if(res.status=='SUCCESS') {
        getCourseName();
    }
}

//获取书名
function getCourseName(){
    var  data={};
    AjaxSubmit2("GET",data, basePath + "/super/common/zhejiang/listBook",listBook_fun);
}
function listBook_fun(res){
   //console.log(res);
    if(res.status=='SUCCESS') {
        var bookLists = res.obj;
        if (bookLists.length != 0) {
            $("#chooseTest").empty();
            $.each(bookLists, function (i, bookList) {
                if(bookList.useType!="THE_USE_OF_THE_TEACHING_MATERIALS_IN_THE_ELECTIVE_COURSE_OF_IDEOLOGICAL_AND_POLITICAL_AFFAIRS") {
                    if(i==type){
                        $("#chooseTest").append('<option data-typeid='+bookList.id+' data-id="'+i+'" selected>'+bookList.bookName+'</option>');
                        var mainPointsOfTeaching = bookList.mainPointsOfTeaching
                        $(".py-mainPinfo").html(mainPointsOfTeaching);
                    }else{
                        $("#chooseTest").append('<option data-typeid='+bookList.id+' data-id="'+i+'">'+bookList.bookName+'</option>');
                    }

                }
            })
        }
    }
}

//改名字
function editBookName(btn){
    var newName = $(".bookName").val();
    var  data={bookId:bookid,bookName: newName};
   //console.log(data);
    AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/updateBookName",updateBookName_fun);
    $("#editTestT").modal("hide");
}
function updateBookName_fun(res){
   //console.log(res);
    if(res.status=='SUCCESS'){
        getCourseName();
    }
}

/*删除图文消息*/
function deleteNews(btn){
    var msg = "您真的确定要删除吗？\n\n请确认！";
    if (confirm(msg)==true){
        var newsId = $(btn).attr("data-id");
        var  data={commonNewsId: newsId};
        var newsTypeId = $(btn).attr("data-newstypeId");
        AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/deleteCommonNews",deleteCommonNews_fun);
        function deleteCommonNews_fun(res){
            /*console.log(res)*/
            if(res.status=='SUCCESS'){
             index =0;
                /*console.log(index)*/
                if(newsTypeId==7){
                    geteducationExample();
                }else if(newsTypeId==8){
                    getqianYan()
                }
            }
        }
    }else{
        return false;
    }

}

//判断字符不空就存
function juge(obj){
    var result={};
    for(i in obj){
        if(obj[i]==null||obj[i]==""){
            continue;
        }
        var value=obj[i];
        eval("result."+i+"='"+value+"'");
    }
    return result;
}

// ZTREE
var newCount = 1;
function addHoverDom(treeId, treeNode) {
    var sObj = $("#" + treeNode.tId + "_span");
    if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
        + "' title='add node' onfocus='this.blur();'></span>";
    sObj.after(addStr);
    var btn = $("#addBtn_" + treeNode.tId);
    if (btn) btn.bind("click", function () {//添加节点
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.addNodes(treeNode, {id: (100 + newCount), pId: treeNode.id, name: "new node" + (newCount++)});
       /* return false;*/
    });
    /*getChapterByBookId();*/
}

function removeHoverDom(treeId, treeNode) {
    $("#addBtn_" + treeNode.tId).unbind().remove();
}

function zTreeOnClick(event, treeId, treeNode) {
    if (treeNode.pId === 0) {
        chapterId = treeNode.id;
        initChapterResource();
    } else {
        sectionId = treeNode.id-1000;
        initSectionResource();
    }
}

//改变状态UP
function changeStatu(btn){
    var newsId = $(btn).attr("data-id");
    var  data={commonNewsId: newsId,status:"UP"};
    var newsTypeId = $(btn).attr("data-newstypeId");
    AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/changeCommonNewsStatus",changeCommonNewsStatus_fun);
    function changeCommonNewsStatus_fun(res){
       //console.log(res)
        if(res.status=='SUCCESS'){
            index = $(btn).parent().parent().parent().parent().next().find(".pagination").find(".active").find("a").text()-1;
            if(newsTypeId==7){
                geteducationExample();
            }else if(newsTypeId==8){
                getqianYan();
            }
        }
    }
}

//改变状态DOWN
function changeStatu2(btn){
    var newsId = $(btn).attr("data-id");
    var  data={commonNewsId: newsId,status:"DOWN"};
    var newsTypeId = $(btn).attr("data-newstypeId");
    AjaxSubmit("POST",data, basePath + "/super/common/zhejiang/changeCommonNewsStatus",changeCommonNewsStatus_fun);
    function changeCommonNewsStatus_fun(res){
       //console.log(res)
        if(res.status=='SUCCESS'){
            index = $(btn).parent().parent().parent().parent().next().find(".pagination").find(".active").find("a").text()-1;
            if(newsTypeId==7){
                geteducationExample();
            }else if(newsTypeId==8){
                getqianYan();
            }
        }
    }
}
